﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text.RegularExpressions;

namespace IloveRSS.Core
{
    public class TextConverter
    {
        public static IEnumerable<String> ConvertToSiteList(String site1, String site2, String site3)
        {
            List<String> result = new List<String>();
            if (site1.Length != 0)
            {
                result.Add(site1);
            }
            if (site2.Length != 0)
            {
                result.Add(site2);
            }
            if (site3.Length != 0)
            {
                result.Add(site3);
            }
            return result;
        }

        public static IEnumerable<String> ConvertToTagList(String tags)
        {
            List<String> result = tags.Split(new char[] { ',', ' ' }).ToList<String>();
            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] == "")
                {
                    result.RemoveRange(i, 1);
                    i--;
                }
            }
            return result;
        }

        public static bool TagsAreNotValid(string tags)
        {
            String pattern = @"[^\sа-яА-Яa-zA-Z_0-9\-,]+";
            return Regex.IsMatch(tags, pattern, RegexOptions.IgnoreCase) || (tags.Length == 0);
        }

    }
}